<?php

class SetupController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$this -> _forward('license');
	}

	public function licenseAction()
	{
		$form = $this -> view -> form = new Install_Form_Setup_License;

		// get request
		$req = $this -> getRequest();

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$url = Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'require'), 'setup', true);

			$this -> _helper -> redirector -> gotoUrl($url, array('prependBase' => false));
		}
	}

	public function requireAction()
	{
	    require_once INSTALL_PATH . '/apis/Check.php';
        
		$form = $this -> view -> form = new Install_Form_Setup_Require;

		$req = $this -> getRequest();
        
        $this->view->check = $check = new Install_Api_Check ;

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$url = Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'database'), 'setup', true);

			$this -> _helper -> redirector -> gotoUrl($url, array('prependBase' => false));
		}
	}

	public function databaseAction()
	{
		$form = $this -> view -> form = new Install_Form_Setup_Database;

		$req = $this -> getRequest();

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$url = Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'account'), 'setup', true);

			$this -> _helper -> redirector -> gotoUrl($url, array('prependBase' => false));
		}
	}
	
	public function accountAction()
	{
		$form = $this -> view -> form = new Install_Form_Setup_Account;

		$req = $this -> getRequest();

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$url = Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'siteinfo'), 'setup', true);

			$this -> _helper -> redirector -> gotoUrl($url, array('prependBase' => false));
		}
	}
	
	public function siteinfoAction()
	{
		$form = $this -> view -> form = new Install_Form_Setup_Siteinfo;

		$req = $this -> getRequest();

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$url = Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'complete'), 'setup', true);

			$this -> _helper -> redirector -> gotoUrl($url, array('prependBase' => false));
		}
	}
	
	public function completeAction(){
		$req = $this -> getRequest();
	}
}
